package cn.vawn.exam.service.impl;

import cn.vawn.exam.entity.Answer;
import cn.vawn.exam.mapper.AnswerMapper;
import cn.vawn.exam.service.IAnswerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("answerService")
public class AnswerServiceImpl implements IAnswerService {

	private static Logger logger = LoggerFactory.getLogger(AnswerServiceImpl.class);

	@Resource
	private AnswerMapper answerMapper;
	
	/*****
	 *
	 */
	public String addAnswersBatch(List<Answer> answers) {
		//������������
		int num = answerMapper.batchInsertAnswer(answers);
		logger.info(num + "");
		StringBuilder answerIds = new StringBuilder();
		for (int i = 0; i < answers.size(); i++) {
			logger.info(answers.get(i).getId() + "");
			answerIds.append(answers.get(i).getId());
			if(i != answers.size() - 1) {
				answerIds.append(",");
			}
		}
		for(Answer a : answers) {
			logger.info(a.getId() + "");
		}
		logger.info(answerIds + "");
		return answerIds.toString();
	}

	/********
	 *
	 */
	@Override
	public List<Answer> batchSelectAnswers(List<Integer> answerIds) {
		return answerMapper.batchSelectAnswers(answerIds);
	}

	/****
	 *
	 */
	@Override
	public void batchUpdateAnswers(List<Answer> answers) {
		answerMapper.batchUpdateAnswers(answers);
	}

	@Override
	public String getLocalUnitermIds(int answerId) {
		return answerMapper.getLocalUnitermIdsByAnswerId(answerId);
	}

	@Override
	public void batchDelete(List<Integer> answerIds) {
		answerMapper.batchDelete(answerIds);
	}

}
